package com.info.zhiduoduo.repository.mapper.partner;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.partner.PartnerWithdrawRecordDto;
import com.info.zhiduoduo.repository.entity.partner.PartnerWithdraw;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 合伙人账户提现记录表 Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2019-06-23
 */
public interface PartnerWithdrawMapper extends BaseMapper<PartnerWithdraw> {

    @Select(" select * from zdd_partner_withdraw where date(createtime) = curdate() and partnerid = #{partnerid} ")
    PartnerWithdraw getTodayDataByPartnerId(@Param("partnerid") int partnerid);

    //根据合伙人ID和状态取出所需数据
    @Select("select * from zdd_partner_withdraw where partnerid = #{partnerid} and state = #{state}")
    List<PartnerWithdraw> getWithdrawByPartnerIdAndState(@Param("partnerid") int partnerid, @Param("state") int state);

    @Select(" select * from zdd_partner_withdraw where state = 2")
    List<PartnerWithdraw> getInProcessWithdraws();

    @Select(" select count(*) from zdd_partner_withdraw where state = 0")
    int countApplyingWithdraws();

    @Select(" select pw.* " +
            " from zdd_partner_withdraw pw " +
            " where if(#{state}=0,1=1,pw.state=#{state}) " +
            " and pw.createtime between #{startDate} and #{endDate} " +
            " and pw.acctname like '%${name}%' " +
            " order by pw.wdid DESC ")
    List<PartnerWithdraw> getWithdrawList(@Param("name") String name, @Param("state") int state, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    @Select(" select pw.wdid AS id,pw.wdno,pw.partnerid,pw.amount,pw.state,pw.createtime,1 AS remitType, pa.realname " +
            " from zdd_partner_withdraw pw " +
            " join zdd_partner_account pa on pa.partnerid = pw.partnerid " +
            " where pw.partnerid = #{userid} " +
            " order by id desc ")
    List<PartnerWithdrawRecordDto> listWithdrawRecord(int userid);
}
